package com.sykj.manage.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sykj.manage.service.NurseTypeService;
import com.sykj.model.NurseType;
import com.sykj.util.ManageBody;


@Controller
@RequestMapping("/nursetype")
public class NurseTypeController {
	
	@Autowired
	NurseTypeService nursetypeService;
	
	@RequestMapping("/nurse")
	@ResponseBody
	public ManageBody index(Model mav,NurseType nurse) {
		System.out.println(nurse.getType_name()+"======================");
		List<NurseType> nu = nursetypeService.getAll(nurse);
		
		return ManageBody.getData(nu.size(), nu, "");
		
	}
	
	@RequestMapping("/del/{type_id}")
	public String del(@PathVariable("type_id") String type_id, Model model) {
		//根据id获取所选对象数据
		int cnt = nursetypeService.del(type_id);
		System.out.println("成功删除" + cnt+"条记录");
		return "redirect:/nursetype";
	}
	
	@RequestMapping("/add")
	public String add(NurseType nursetype ,Model model) {
		System.out.println("==================="+nursetype+"==================");
		//nursetype.setCreate_time(new Date());
		int cnt = nursetypeService.add(nursetype);
		System.out.println("成功插入了"+cnt+"条数据，ID是："+nursetype.getType_id());
		return "redirect:/nursetype/nursetype.html";
	}
	
	@RequestMapping("/update/{type_id}")
	@ResponseBody
	public Object update(@PathVariable("type_id") String type_id ,Model model) {
		System.out.println("==================="+type_id+"==================");
		NurseType findAllById = nursetypeService.findAllById(type_id);
		System.out.println("============"+findAllById+"============");
		return findAllById;
	}
	@RequestMapping("/up")
	public String up(NurseType type,Model model) {
		System.out.println("==================="+type+"==================");
		int update = nursetypeService.update(type);
		System.out.println("============"+update+"============");
		return "redirect: /nursetype/nursetype.html";
	}
}
